package CtrLayer;

import java.util.ArrayList;

import DBLayer.*;
import ModelLayer.*;

public class RangeCtr {
	
private static RangeCtr instance;
	
	private RangeCtr()
	{
		
	}
	
	public static RangeCtr getInstance()
    {
        if(instance==null)
        {
            instance = new RangeCtr();
        }
        return instance;
    }
	
	public ArrayList<Range> findAllRanges()
	{
		IFDBRange dbR = new DBRange();
	    ArrayList<Range> allR = new ArrayList<Range>();
	    allR = dbR.getAllRanges(false);
	    return allR;
	}
	
	public Range findByName(String rangeName)
    {
        IFDBRange dbR = new DBRange();
        return dbR.searchRangeName(rangeName);
    }
	
	public Range findByRangeId(int rangeId)
    {
        IFDBRange dbR = new DBRange();
        return dbR.findRange(rangeId, true);
    }
	
	public int deleteByRangeId(int rangeId)
    {
        IFDBRange dbR = new DBRange();
        return dbR.deleteRange(rangeId);
    }
	
	public int updateRange(int rangeId, String rangeName)
    {
        IFDBRange dbR = new DBRange();
        Range r = new Range();
        r.setRangeID(rangeId);
        r.setRangeName(rangeName);
        return  dbR.updateRange(r);
    }
	public void createRange(String rangeName)
    {    
         Range rObj = new Range();
         rObj.setRangeName(rangeName);
         
         try{
          DbConnection1.startTransaction();
          DBRange dbR = new DBRange();
          dbR.insertRange(rObj);
          DbConnection1.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection1.rollbackTransaction();
         }
    }

}
